<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>小程序初学笔记 | Hexo</title><meta name="author" content="Joey"><meta name="copyright" content="Joey"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="轮播图组件Swiper根据官方API swiper 是滑块视图容器 ，只可放置swiper-item组件 。  swiper-item : 宽高会自动设置为100%。 其属性在v1.9.0版有：   item-id ：string 型， 为该项标识符  skip-hidden-item-layout ：boolean型，是否跳过未显示的滑块布局    通过给swiper 设置其属性 如 autop">
<meta property="og:type" content="article">
<meta property="og:title" content="小程序初学笔记">
<meta property="og:url" content="https://jonhsean.gitee.io/blog/2022/08/26/daily/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%BC%80%E5%8F%91%E7%AC%94%E8%AE%B0/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="轮播图组件Swiper根据官方API swiper 是滑块视图容器 ，只可放置swiper-item组件 。  swiper-item : 宽高会自动设置为100%。 其属性在v1.9.0版有：   item-id ：string 型， 为该项标识符  skip-hidden-item-layout ：boolean型，是否跳过未显示的滑块布局    通过给swiper 设置其属性 如 autop">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2020/05/01/gkihqEjXxJ5UZ1C.jpg">
<meta property="article:published_time" content="2022-08-25T16:05:37.000Z">
<meta property="article:modified_time" content="2022-09-25T12:28:12.838Z">
<meta property="article:author" content="Joey">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2020/05/01/gkihqEjXxJ5UZ1C.jpg"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="https://jonhsean.gitee.io/blog/2022/08/26/daily/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%BC%80%E5%8F%91%E7%AC%94%E8%AE%B0/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://unpkg.com/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://unpkg.com/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: {"path":"/blog/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":100,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: {"limitDay":180,"position":"top","messagePrev":"It has been","messageNext":"days since the last update, the content of the article may be outdated."},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://unpkg.com/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://unpkg.com/flickr-justified-gallery/dist/fjGallery.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isAnchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '小程序初学笔记',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-09-25 20:28:12'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">21</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">26</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">30</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/blog/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">Hexo</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/blog/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">小程序初学笔记</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-08-25T16:05:37.000Z" title="发表于 2022-08-26 00:05:37">2022-08-26</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-09-25T12:28:12.838Z" title="更新于 2022-09-25 20:28:12">2022-09-25</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.4k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>10分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="小程序初学笔记"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><h2 id="轮播图组件Swiper"><a href="#轮播图组件Swiper" class="headerlink" title="轮播图组件Swiper"></a>轮播图组件Swiper</h2><p>根据官方<a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html">API</a></p>
<p><code>swiper</code> 是滑块视图容器 ，只可放置<code>swiper-item</code>组件 。</p>
<blockquote>
<p>swiper-item : 宽高会自动设置为100%。</p>
<p>其属性在<code>v1.9.0</code>版有：</p>
<ul>
<li><p> <code>item-id</code> ：string 型， 为该项标识符</p>
</li>
<li><p><code>skip-hidden-item-layout</code> ：boolean型，是否跳过未显示的滑块布局</p>
</li>
</ul>
</blockquote>
<p>通过给swiper 设置其属性 如 <code>autoplay</code>: <strong>true</strong>;  就会自动播放。</p>
<p>so, 使用方式就是通过给各个标签设置 <code>class名</code>  , 用样式来控制显示形式。</p>
<p>用属性控制行为，用事件控制变化等。</p>
<blockquote>
<p><code>v1.0.0版</code> 部分属性如下：</p>
<p><code>indicator-dots</code>  [false] ; 是否显示面板指示点</p>
<p><code>autoplay</code>  [false] ; 是否自动切换</p>
<p><code>interval</code> [5000] ; 自动切换时间间隔</p>
<p><code>duration</code> [500] ;   滑动动画时长</p>
<p><code> current</code> [0 : number] ;  当前所在滑块的 index</p>
</blockquote>
<h3 id="代码如下"><a href="#代码如下" class="headerlink" title="代码如下:"></a>代码如下:</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;page-section page-section-spacing swiper&quot;</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">swiper</span> <span class="attr">indicator-dots</span>=<span class="string">&quot;&#123;&#123;indicatorDots&#125;&#125;&quot;</span></span></span><br><span class="line"><span class="tag">              <span class="attr">autoplay</span>=<span class="string">&quot;&#123;&#123;autoplay&#125;&#125;&quot;</span> </span></span><br><span class="line"><span class="tag">              <span class="attr">interval</span>=<span class="string">&quot;&#123;&#123;interval&#125;&#125;&quot;</span> </span></span><br><span class="line"><span class="tag">              <span class="attr">duration</span>=<span class="string">&quot;&#123;&#123;duration&#125;&#125;&quot;</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">block</span> <span class="attr">wx:for</span>=<span class="string">&quot;&#123;&#123;background&#125;&#125;&quot;</span> <span class="attr">wx:key</span>=<span class="string">&quot;*this&quot;</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">swiper-item</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;swiper-item &#123;&#123;item&#125;&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">view</span>&gt;</span>  #item用于标志类名 设置不同背景色</span><br><span class="line">          <span class="tag">&lt;/<span class="name">swiper-item</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">block</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">swiper</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h3 id="自定义指示器"><a href="#自定义指示器" class="headerlink" title="自定义指示器"></a>自定义指示器</h3><ol>
<li>通过绑定 <strong>swiper</strong> <code>change</code>事件， 获取当前的 <code>index</code></li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;swiper bindchange=&quot;swiperFn&quot;&gt; ... &lt;/swiper&gt;</span><br><span class="line"></span><br><span class="line">js:</span><br><span class="line">  swiperFn(e)&#123;</span><br><span class="line">		console.log(e.detail.current)  // 拿到index</span><br><span class="line">    &#125;)</span><br></pre></td></tr></table></figure>



<ol start="2">
<li>自定义指示器 通过<strong>判断</strong> <code>index</code> 是否为真，则增加样式</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"># 样式 子绝父相，右下。 item项 排列方式左浮动 &amp; 左外边距 &amp;  变圆</span><br><span class="line">## active 样式  width加长 &amp; 背景变色</span><br><span class="line">&lt;view class=&quot;swiper&quot;&gt;</span><br><span class="line">      ...swiper 及 swiper-item 组件 ...</span><br><span class="line">    </span><br><span class="line">    &lt;view class=&quot;indicator&quot;&gt;</span><br><span class="line">        &lt;view wx:for=&quot;&#123;&#123;background&#125;&#125;&quot; wx:key=&quot;*this&quot; </span><br><span class="line">            class=&quot;&#123;&#123;index == swiperNum? &#x27;active&#x27; : &#x27;&#x27;&#125;&#125;&quot;&gt;</span><br><span class="line">        &lt;/view&gt;</span><br><span class="line">    &lt;/view&gt;</span><br><span class="line">&lt;/view&gt;</span><br><span class="line">    </span><br><span class="line">#js : 将swiperNum 设为 index</span><br><span class="line"></span><br><span class="line">data:&#123;</span><br><span class="line">	...</span><br><span class="line">	swiperNum: 0</span><br><span class="line">&#125;,</span><br><span class="line">swiperFn(e)&#123;</span><br><span class="line">	this.setData(&#123;</span><br><span class="line">		swiperNum: e.detail.current</span><br><span class="line">	&#125;)</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>







<hr>
<h3 id="完整代码区："><a href="#完整代码区：" class="headerlink" title="完整代码区："></a>完整代码区：</h3><ol>
<li><strong>home.wxml</strong></li>
</ol>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;page-section page-section-spacing swiper&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">swiper</span> <span class="attr">autoplay</span>=<span class="string">&quot;&#123;&#123;autoplay&#125;&#125;&quot;</span> <span class="attr">interval</span>=<span class="string">&quot;&#123;&#123;interval&#125;&#125;&quot;</span> <span class="attr">duration</span>=<span class="string">&quot;&#123;&#123;duration&#125;&#125;&quot;</span> <span class="attr">bindchange</span>=<span class="string">&quot;swiperFn&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">block</span> <span class="attr">wx:for</span>=<span class="string">&quot;&#123;&#123;background&#125;&#125;&quot;</span> <span class="attr">wx:key</span>=<span class="string">&quot;*this&quot;</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">swiper-item</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">image</span> <span class="attr">src</span>=<span class="string">&quot;&#123;&#123;item&#125;&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">image</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">swiper-item</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">block</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">swiper</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;indicator&quot;</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">view</span> <span class="attr">wx:for</span>=<span class="string">&quot;&#123;&#123;background&#125;&#125;&quot;</span> <span class="attr">wx:key</span>=<span class="string">&quot;*this&quot;</span> <span class="attr">class</span>=<span class="string">&quot;&#123;&#123;index == swiperNum? &#x27;active&#x27; : &#x27;&#x27;&#125;&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br></pre></td></tr></table></figure>

<ol start="2">
<li><strong>home.wxss</strong></li>
</ol>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* swiper */</span></span><br><span class="line"><span class="selector-class">.swiper</span>, swiper,image&#123;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line">  <span class="attribute">height</span>: <span class="number">500</span>rpx;</span><br><span class="line">  <span class="attribute">display</span>: block;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-class">.swiper</span>&#123;</span><br><span class="line">  <span class="attribute">position</span>: relative;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 指示器 */</span></span><br><span class="line"><span class="selector-class">.indicator</span>&#123;</span><br><span class="line">  <span class="attribute">position</span>: absolute;</span><br><span class="line">  <span class="attribute">bottom</span>: <span class="number">20</span>rpx;</span><br><span class="line">  <span class="attribute">right</span>: <span class="number">20</span>rpx;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-class">.indicator</span> view&#123;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">30</span>rpx;</span><br><span class="line">  <span class="attribute">height</span>: <span class="number">30</span>rpx;</span><br><span class="line">  <span class="attribute">background</span>: <span class="number">#ccc</span>;</span><br><span class="line">  <span class="attribute">border-radius</span>: <span class="number">30</span>rpx;</span><br><span class="line">  <span class="attribute">float</span>: left;</span><br><span class="line">  <span class="attribute">margin-left</span>: <span class="number">20</span>rpx;</span><br><span class="line">  <span class="attribute">transition</span>: all <span class="number">1s</span> linear;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 指示器active */</span></span><br><span class="line"><span class="selector-class">.indicator</span> view<span class="selector-class">.active</span>&#123;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">50</span>rpx;</span><br><span class="line">  <span class="attribute">background</span>: <span class="number">#34399c</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="3">
<li><strong>home.js</strong></li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">Page</span>(&#123;</span><br><span class="line">  <span class="attr">data</span>: &#123;</span><br><span class="line">    <span class="attr">background</span>:[</span><br><span class="line">      <span class="string">&#x27;/images/banner/baner1.jpg&#x27;</span>,</span><br><span class="line">      <span class="string">&#x27;/images/banner/baner2.jpg&#x27;</span>,</span><br><span class="line">      <span class="string">&#x27;/images/banner/baner3.jpg&#x27;</span>,</span><br><span class="line">      <span class="string">&#x27;/images/banner/baner4.jpg&#x27;</span></span><br><span class="line">    ],</span><br><span class="line">    <span class="attr">autoplay</span>: <span class="literal">true</span>,</span><br><span class="line">    <span class="attr">interval</span>: <span class="number">2000</span>,</span><br><span class="line">    <span class="attr">duration</span>: <span class="number">500</span>,</span><br><span class="line">    <span class="attr">swiperNum</span>: <span class="number">0</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="title function_">swiperFn</span>(<span class="params">e</span>)&#123;</span><br><span class="line">    <span class="variable language_">this</span>.<span class="title function_">setData</span>(&#123;</span><br><span class="line">      <span class="attr">swiperNum</span>:e.<span class="property">detail</span>.<span class="property">current</span></span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<ol start="4">
<li><strong>home.json</strong></li>
</ol>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;navigationStyle&quot;</span><span class="punctuation">:</span> <span class="string">&quot;custom&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>

<hr>
<p>-参考：<a target="_blank" rel="noopener" href="http://codesohigh.com/subject/mp/day02.html#%E5%9B%9B%E3%80%81swiper%E7%BB%84%E4%BB%B6%E3%80%90%E7%86%9F%E7%BB%83%E3%80%91">笔记</a></p>
<hr>
<h2 id="scroll-view-组件"><a href="#scroll-view-组件" class="headerlink" title="scroll-view 组件"></a>scroll-view 组件</h2><p>官方<a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html">文档</a></p>
<hr>
<p>注： 官方示例代码中，三个展示<code>view 样式</code>  背景色等是写在 <code>app.wxss</code>中， 且用的<strong>伪元素</strong>放置文字ABC</p>
<hr>
<blockquote>
<p> 可滚动视图区域。使用<strong>竖向</strong>滚动时，需要给<a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html">scroll-view</a>一个<strong>固定高度</strong>，通过 WXSS 设置 height。组件属性的长度单位默认为<code>px</code>，<a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">2.4.0</a>起支持传入单位(rpx/px)。</p>
</blockquote>
<p>其属性：</p>
<blockquote>
<p> <code>scroll-x</code>  [false] ; 允许横向滚动</p>
<p><code>scroll-y</code>   [false] ; 允许纵向滚动</p>
<p><code>scroll-top</code> [number/string] ; 设置竖向滚动条位置</p>
<p><code> scroll-left</code>  [number/string] ; 设置横向滚动条位置</p>
<p><code> scroll-into-view</code>  [string] ;    值应为某子元素id（id不能以数字开头）。设置哪个方向可滚动，则在哪个方向滚动到该元素     ;   优先级高于<code>scroll-top</code></p>
<p><code> bindscrolltoupper</code>  [eventhandle]  ; 滚动到顶部/左边时触发</p>
<p><code>bindscrolltolower</code>  [eventhandle] ;  滚动到底部/右边时触发</p>
</blockquote>
<h3 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h3><ol>
<li><p><strong>a.wxml</strong></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">//横向：</span><br><span class="line"><span class="tag">&lt;<span class="name">scroll-view</span> <span class="attr">scroll-x</span>=<span class="string">&quot;true&quot;</span> <span class="attr">style</span>=<span class="string">&quot;width: 100%&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">view</span> <span class="attr">wx:for</span>=<span class="string">&quot;&#123;&#123;arr&#125;&#125;&quot;</span> <span class="attr">wx:key</span>=<span class="string">&quot;*this&quot;</span> </span></span><br><span class="line"><span class="tag">          <span class="attr">class</span>=<span class="string">&quot;scroll-view-item demo-text-1&quot;</span>&gt;</span></span><br><span class="line">    	<span class="tag">&lt;<span class="name">image</span> <span class="attr">src</span>=<span class="string">&quot;&#123;&#123;item.src&#125;&#125;&quot;</span>  <span class="attr">mode</span>=<span class="string">&quot;widthFix&quot;</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">text</span>&gt;</span>&#123;&#123;item.text&#125;&#125;<span class="tag">&lt;/<span class="name">text</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">scroll-view</span>&gt;</span></span><br></pre></td></tr></table></figure></li>
<li><p><strong>b.wxss</strong></p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 控制元素排成一行  */</span></span><br><span class="line">scroll-view&#123;</span><br><span class="line">    <span class="attribute">white-space</span>: nowrap;  #重点<span class="number">1</span>： 父元素文本不换行：子成一排</span><br><span class="line">    <span class="attribute">height</span>:<span class="number">210</span>rpx;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 每个view 宽，行内块元素 */</span></span><br><span class="line"><span class="selector-class">.scroll-view-item</span>&#123;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">35%</span>;</span><br><span class="line">  <span class="attribute">display</span>: inline-block;   #重点<span class="number">2</span>：  子元素ib :排成一排</span><br><span class="line">    </span><br><span class="line">  margin-right: <span class="number">20</span>rpx;</span><br><span class="line">  <span class="attribute">border-radius</span>: <span class="number">6</span>rpx;</span><br><span class="line">  <span class="attribute">box-shadow</span>: <span class="number">0</span> <span class="number">0</span> <span class="number">10</span>rpx <span class="number">#666</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* img */</span></span><br><span class="line"><span class="selector-class">.scroll-view-item</span> image&#123;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line">  <span class="attribute">display</span>: block;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* text */</span></span><br><span class="line"><span class="selector-class">.scroll-view-item</span> text&#123;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line">  <span class="attribute">display</span>: block;</span><br><span class="line">  <span class="attribute">text-align</span>: center;</span><br><span class="line">  <span class="attribute">height</span>: <span class="number">40</span>rpx;</span><br><span class="line">  <span class="attribute">line-height</span>: <span class="number">40</span>rpx;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 安卓出现丑滚动条 优化： */</span></span><br><span class="line">::-webkit-scrollbar&#123;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">0</span>;</span><br><span class="line">  <span class="attribute">height</span>: <span class="number">0</span>;</span><br><span class="line">  <span class="attribute">color</span>:transparent;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>js 传入image的 url &amp;  name</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">data</span>:&#123;</span><br><span class="line">    <span class="attr">arr</span>:[&#123;<span class="attr">src</span>: <span class="string">&quot;/images/home/card01.jpg&quot;</span>,<span class="attr">text</span>: <span class="string">&#x27;给特别的你&#x27;</span>&#125;,</span><br><span class="line">         &#123;<span class="attr">src</span>: <span class="string">&quot;/images/home/card02.jpg&quot;</span>,<span class="attr">text</span>: <span class="string">&#x27;我想对你说&#x27;</span>&#125;,</span><br><span class="line">         &#123;<span class="attr">src</span>: <span class="string">&quot;/images/home/card03.jpg&quot;</span>,<span class="attr">text</span>: <span class="string">&#x27;勇敢爱&#x27;</span>&#125;,</span><br><span class="line">         &#123;<span class="attr">src</span>: <span class="string">&quot;/images/home/card04.jpg&quot;</span>,<span class="attr">text</span>: <span class="string">&#x27;一个人的精彩&#x27;</span>&#125;</span><br><span class="line">        ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>—end</p>
<hr>
</li>
</ol>
<h3 id="Q-scroll-view组件"><a href="#Q-scroll-view组件" class="headerlink" title="Q scroll-view组件"></a>Q scroll-view组件</h3><ol>
<li><p>使用<strong>Flex</strong> 布局效果。</p>
<p>法1 ：  得开启属性： <code> enable-flex</code>  (V<a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">2.7.3</a>)  </p>
<p>​            flex css属性才会生效。否则无用。 【不好用，直接子节点item 高度不限制则无限高。】</p>
<p>法2： 使用<code>view</code> 包裹住循环遍历的 scroll-item 节点。 -<a target="_blank" rel="noopener" href="https://segmentfault.com/a/1190000017898725">文</a></p>
<p>法3 ： 使用 <code>display:inblock</code> + <code>white-space: nowrap</code> 实现一行效果。 </p>
<p>法4： 父元素使用<code>.parent &#123;display:flex; white-space: nowrap&#125; </code>规定段落中的文本不进行换行。子元素设置<code>.children &#123;display:inline-flex&#125;；</code>可以实现横向滚动。</p>
</li>
</ol>
<hr>
<p>四张图片接口：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">https://yanxuan.nosdn.127.net/31da695c84cabd0eaff054265da29e5c.jpg?imageView&amp;quality=75&amp;thumbnail=750x0</span><br><span class="line"></span><br><span class="line">https://yanxuan.nosdn.127.net/baea18aa59217cabd190b19fc1cf1617.jpg?imageView&amp;quality=75&amp;thumbnail=750x0</span><br><span class="line"></span><br><span class="line">https://yanxuan.nosdn.127.net/d5683f01e132851229be21c52d808b62.jpg?imageView&amp;quality=75&amp;thumbnail=750x0</span><br><span class="line"></span><br><span class="line">https://yanxuan.nosdn.127.net/af7d906e174cb160ab5a979310aa223d.jpg?imageView&amp;quality=75&amp;thumbnail=750x0</span><br></pre></td></tr></table></figure>

<ol>
<li>咖啡馆 2. 严选。</li>
</ol>
<hr>
<h2 id="window"><a href="#window" class="headerlink" title="window"></a>window</h2><p>其他导航部位的设置方式：</p>
<p>根据官方 <a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/page.html">文档</a> ，对单个页面进行配置，可以在页面对应的 <code>.json</code> 文件来对本页面的表现进行配置。</p>
<p>这里不需要额外指定 <code>window</code> 字段，直接配置window 中的内容：</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// /pages/menu.json文件:</span></span><br><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">    <span class="comment">//无需放入window项内，直接使用：</span></span><br><span class="line">    <span class="attr">&quot;backgroundTextStyle&quot;</span><span class="punctuation">:</span> <span class="string">&quot;light&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;navigationBarBackgroundColor&quot;</span><span class="punctuation">:</span> <span class="string">&quot;#0000ff&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;navigationBarTitleText&quot;</span><span class="punctuation">:</span> <span class="string">&quot;欢迎来到咖啡店&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;navigationBarTextStyle&quot;</span><span class="punctuation">:</span> <span class="string">&quot;black&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>



<h3 id="沉浸式导航"><a href="#沉浸式导航" class="headerlink" title="沉浸式导航"></a>沉浸式导航</h3><p>在对应页面的 配置文件<code>json</code>中 设置导航栏样式为 <strong>自定义导航栏</strong> ：</p>
<p>添加项 ： <code>&quot;navigationStyle&quot;: &quot;custom&quot;</code>  # 只保留右上角胶囊按钮。</p>
<hr>
<h2 id="获取元素的高"><a href="#获取元素的高" class="headerlink" title="获取元素的高"></a>获取元素的高</h2><p>官方<a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/api/wxml/wx.createSelectorQuery.html">文档</a></p>
<p>官方示例：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> query = wx.<span class="title function_">createSelectorQuery</span>()  <span class="comment">// 返回一个 SelectorQuery 对象实例。</span></span><br><span class="line"><span class="comment">// 在自定义组件或包含自定义组件的页面中，应使用 this.createSelectorQuery() 来代替。</span></span><br><span class="line"></span><br><span class="line">query.<span class="title function_">select</span>(<span class="string">&#x27;#the-id&#x27;</span>).<span class="title function_">boundingClientRect</span>()</span><br><span class="line">query.<span class="title function_">selectViewport</span>().<span class="title function_">scrollOffset</span>()</span><br><span class="line">query.<span class="title function_">exec</span>(<span class="keyword">function</span>(<span class="params">res</span>)&#123;</span><br><span class="line">  res[<span class="number">0</span>].<span class="property">top</span>       <span class="comment">// #the-id节点的上边界坐标</span></span><br><span class="line">  res[<span class="number">1</span>].<span class="property">scrollTop</span> <span class="comment">// 显示区域的竖直滚动位置</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>







<hr>
<h2 id="wxss"><a href="#wxss" class="headerlink" title="wxss"></a>wxss</h2><h3 id="view-中-标签：text"><a href="#view-中-标签：text" class="headerlink" title="view 中 标签：text"></a>view 中 标签：text</h3><p>要直接包包裹， 如果换行会不排空的。 view会展示换行(包含换行符在内)。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;h2&quot;</span>&gt;</span>&#123;&#123;item.title&#125;&#125;<span class="tag">&lt;<span class="name">text</span> <span class="attr">class</span>=<span class="string">&quot;price&quot;</span> &gt;</span>&#123;&#123;1)&#125;&#125;&lt;/text &gt;起<span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"></span><br><span class="line"># 与 它 显示的结果完全不同。</span><br><span class="line"><span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;h2&quot;</span>&gt;</span>&#123;&#123;item.title&#125;&#125;</span><br><span class="line">    <span class="tag">&lt;<span class="name">text</span> <span class="attr">class</span>=<span class="string">&quot;price&quot;</span> &gt;</span>&#123;&#123;1)&#125;&#125;&lt;/text &gt;起</span><br><span class="line"><span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>







<hr>
<h2 id="WXS"><a href="#WXS" class="headerlink" title="WXS"></a>WXS</h2><p>官方文档- <a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxs/">文</a></p>
<p>！不能使用 let 声明变量，会<code>语法报错</code>。</p>
<h3 id=""><a href="#" class="headerlink" title=""></a></h3><blockquote>
<p> 1.无法使用<code>es6</code>的语法  (let const ….)</p>
<p><code>new Date()</code> 无法使用，需要使用<code>getDate()</code>代替</p>
<p>导出函数也不能使用缩写</p>
</blockquote>
<hr>
<p>img: </p>
<p>   遮罩文字： <code>filter: brightness(60%);</code></p>
<hr>
<h2 id="自定义组件传值-properties"><a href="#自定义组件传值-properties" class="headerlink" title="自定义组件传值 properties"></a>自定义组件传值 properties</h2><h3 id="1-component-内引入了第三方组件。"><a href="#1-component-内引入了第三方组件。" class="headerlink" title="1. component 内引入了第三方组件。"></a>1. component 内引入了第三方组件。</h3><p> 文件： <code>/components/search/search</code>  </p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">// 引入了第三方库 vant ui 的 search组件 </span><br><span class="line">//  需要传值 shape:  需要这样写： 必须同名。</span><br><span class="line"><span class="tag">&lt;<span class="name">van-search</span> <span class="attr">shape</span> = <span class="string">&quot;&#123;&#123;shape&#125;&#125;&quot;</span></span></span><br><span class="line"><span class="tag"> <span class="attr">value</span>=<span class="string">&quot;&#123;&#123; value &#125;&#125;&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;请输入搜索关键词&quot;</span>/&gt;</span></span><br><span class="line"></span><br><span class="line">// shapexyz 即我们的 properties 属性，传入其值 给 shape引用。</span><br></pre></td></tr></table></figure>

<p>JS:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">Component</span>(&#123;</span><br><span class="line">  <span class="attr">properties</span>:&#123;</span><br><span class="line">    <span class="attr">shape</span>:&#123;   </span><br><span class="line">        <span class="attr">type</span>: <span class="title class_">String</span>,</span><br><span class="line">        <span class="attr">value</span>: <span class="string">&#x27;round&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<h3 id="自定义组件样式"><a href="#自定义组件样式" class="headerlink" title="自定义组件样式"></a>自定义组件样式</h3><h4 id="shadow-root"><a href="#shadow-root" class="headerlink" title="#shadow-root"></a>#shadow-root</h4><p>-覆盖掉其css  : <a target="_blank" rel="noopener" href="https://www.cnblogs.com/echohye/p/16631876.html">解决办法</a></p>
<p>-<a target="_blank" rel="noopener" href="https://juejin.cn/post/7034143443681181703">文</a></p>
<p>-<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/Web_Components/Using_shadow_DOM">MDN</a>  -<a target="_blank" rel="noopener" href="https://www.wenjiangs.com/doc/etvtjguo">文</a></p>
<p>-<a target="_blank" rel="noopener" href="https://www.cnblogs.com/songyao666/p/16634947.html">科普</a></p>
<hr>
<p>待看</p>
<p>小程序<a target="_blank" rel="noopener" href="http://www.okeydown.com/html/2019/01-28/1144.html">奇淫技巧</a></p>
<h2 id="报错"><a href="#报错" class="headerlink" title="报错"></a>报错</h2><ol>
<li><p><code>[渲染层网络层错误] Failed to load font</code> <a target="_blank" rel="noopener" href="https://at.alicdn.com/t/font_2553510_iv4v8nulyz.woff2?t=1649083952952">https://at.alicdn.com/t/font_2553510_iv4v8nulyz.woff2?t=1649083952952</a> </p>
<p> <code>net::ERR_CACHE_MISS </code></p>
</li>
</ol>
<p>解决办法： -<a target="_blank" rel="noopener" href="https://blog.csdn.net/qew2017/article/details/104547478">文</a></p>
<p><strong>原因</strong>：异步请求需要一定的时间，而小程序一进页面就开始加载，请求速度没跟上，这时页面显示加载的时候image里面的值是空的，就会出现渲染层、<a target="_blank" rel="noopener" href="https://so.csdn.net/so/search?q=%E7%BD%91%E7%BB%9C%E5%B1%82&spm=1001.2101.3001.7020">网络层</a>错误，</p>
<p><strong>解决：</strong></p>
<p>只需要加上<code>wx:if=&quot;&#123;&#123;arr.length>0&#125;&#125;&quot;</code> 或者<code>wx:if=&quot;&#123;****&#125;&#125;&quot;</code><br>拖延一下加载图片的时间</p>
<p><code>&lt;image wx:if=&quot;&#123;&#123; item.imgSrc &#125;&#125;&quot; src=&quot;&#123;&#123; item.imgSrc &#125;&#125;&quot; </code></p>
<ol start="2">
<li>使用vant的 报错</li>
</ol>
<p>问题1  解法1：  -<a target="_blank" rel="noopener" href="https://blog.csdn.net/m0_65382120/article/details/126632290">文</a>  降低微信库版本 到2.18 即可 </p>
<p>​         <a target="_blank" rel="noopener" href="https://blog.csdn.net/chduguxue/article/details/123298873">解法2</a>   原因是编译xxx文件 小程序编译不了</p>
<hr>
<h2 id="vant-UI"><a href="#vant-UI" class="headerlink" title="vant UI"></a>vant UI</h2><h3 id="Submit-提交订单栏"><a href="#Submit-提交订单栏" class="headerlink" title="Submit 提交订单栏"></a>Submit 提交订单栏</h3><p>Q :  在 tabbar 页面中使用该组件，不生效</p>
<p>​    A： 因为它默认是在底部。所以被 tabbar 给遮住了。</p>
<p>​    S:    使用 外部样式类 给它个 很高的高度 / 外边距 / bottom (需要加标签名增加权重覆盖)</p>
<h3 id="步进器"><a href="#步进器" class="headerlink" title="步进器"></a>步进器</h3><p>貌似异步文案错误  onChange(e) {}  // setData 值应该为 e.detail 而不是 e</p>
<hr>
<h1 id="node"><a href="#node" class="headerlink" title="node"></a>node</h1><p>-<a target="_blank" rel="noopener" href="https://docs.microsoft.com/zh-cn/shows/beginners-series-to-nodejs/?wt.mc_id=academic-13441-cxa">文</a></p>
<p>如何创建新的Node.js项目 [共 26 个]</p>
<hr>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://jonhsean.gitee.io/blog">Joey</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://jonhsean.gitee.io/blog/2022/08/26/daily/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%BC%80%E5%8F%91%E7%AC%94%E8%AE%B0/">https://jonhsean.gitee.io/blog/2022/08/26/daily/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%BC%80%E5%8F%91%E7%AC%94%E8%AE%B0/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://jonhsean.gitee.io/blog" target="_blank">Hexo</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2020/05/01/gkihqEjXxJ5UZ1C.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://unpkg.com/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://unpkg.com/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2022/08/25/daily/%E5%8C%85%E7%AE%A1%E7%90%86/"><img class="prev-cover" src="https://i.loli.net/2020/05/01/gkihqEjXxJ5UZ1C.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">npm参数</div></div></a></div><div class="next-post pull-right"><a href="/blog/2022/08/26/daily/cssUitls/"><img class="next-cover" src="https://i.loli.net/2020/05/01/gkihqEjXxJ5UZ1C.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">css预编语言</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BD%AE%E6%92%AD%E5%9B%BE%E7%BB%84%E4%BB%B6Swiper"><span class="toc-text">轮播图组件Swiper</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81%E5%A6%82%E4%B8%8B"><span class="toc-text">代码如下:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8C%87%E7%A4%BA%E5%99%A8"><span class="toc-text">自定义指示器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%8C%E6%95%B4%E4%BB%A3%E7%A0%81%E5%8C%BA%EF%BC%9A"><span class="toc-text">完整代码区：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#scroll-view-%E7%BB%84%E4%BB%B6"><span class="toc-text">scroll-view 组件</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81"><span class="toc-text">代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Q-scroll-view%E7%BB%84%E4%BB%B6"><span class="toc-text">Q scroll-view组件</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#window"><span class="toc-text">window</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B2%89%E6%B5%B8%E5%BC%8F%E5%AF%BC%E8%88%AA"><span class="toc-text">沉浸式导航</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E5%85%83%E7%B4%A0%E7%9A%84%E9%AB%98"><span class="toc-text">获取元素的高</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#wxss"><span class="toc-text">wxss</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#view-%E4%B8%AD-%E6%A0%87%E7%AD%BE%EF%BC%9Atext"><span class="toc-text">view 中 标签：text</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#WXS"><span class="toc-text">WXS</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-text"></span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E4%BC%A0%E5%80%BC-properties"><span class="toc-text">自定义组件传值 properties</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-component-%E5%86%85%E5%BC%95%E5%85%A5%E4%BA%86%E7%AC%AC%E4%B8%89%E6%96%B9%E7%BB%84%E4%BB%B6%E3%80%82"><span class="toc-text">1. component 内引入了第三方组件。</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E6%A0%B7%E5%BC%8F"><span class="toc-text">自定义组件样式</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#shadow-root"><span class="toc-text">#shadow-root</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8A%A5%E9%94%99"><span class="toc-text">报错</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#vant-UI"><span class="toc-text">vant UI</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Submit-%E6%8F%90%E4%BA%A4%E8%AE%A2%E5%8D%95%E6%A0%8F"><span class="toc-text">Submit 提交订单栏</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%AD%A5%E8%BF%9B%E5%99%A8"><span class="toc-text">步进器</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#node"><span class="toc-text">node</span></a></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2022 By Joey</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="/blog/js/tw_cn.js"></script><script src="https://unpkg.com/@fancyapps/ui/dist/fancybox.umd.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://unpkg.com/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/blog/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://unpkg.com/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script src="https://unpkg.com/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = true;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://unpkg.com/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="true"></script><script src="https://unpkg.com/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"]):not([href="/music/"]):not([href="/no-pjax/"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>